<?php

/*

   Aiesec's OH Management System - to control the Office Hour of Aiesec's Members.
   Copyright (C) 2009 Vinicius Stein Dani

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/

/*
  
   Author: Vinicius Stein Dani
   Contact: viniciussdani@gmail.com
   Today is: March 15, 2009
   Location at this present moment: Santa Maria - RS - Brasil
  
*/

   include_once '_v_geral.php';
  
   $vetor_nome = array();
   $vetor_oh_dia = array();
   $vetor_oh_hora = array();
   $contador = 0;
  
   $a = mysql_query("SELECT nome, oh_dia, oh_hora FROM usuarios ORDER BY nome");
   while($b = mysql_fetch_array($a))
   {
      $nome = $b['nome'];

      $oh_dia = $b['oh_dia'];
      $oh_hora = $b['oh_hora'];
      $oh_hora = date("H:i", $oh_hora);

      $vetor_nome[$contador] = $nome;
      $vetor_oh_dia[$contador] = $oh_dia;
      $vetor_oh_hora[$contador] = $oh_hora;
      
      $contador++;
   }
    
?>

<?php

   

?>

    <table cellpadding="5" cellspacing="5">
      <tr>
        <td class="tabela_oh"><b>Seg</b></td>
        <td class="tabela_oh"><b>Ter</b></td>
        <td class="tabela_oh"><b>Qua</b></td>
        <td class="tabela_oh"><b>Qui</b></td>
        <td class="tabela_oh"><b>Sex</b></td>
      </tr>
      
      <tr>
      
        <?php
         
          $hora = 10;
          $dia = 1;
                              
          // 1 = seg; 2 = ter; 3 = qua; 4 = qui; 5 = sex
         
        ?>
        
        <?php for($i = 1; $i < 56; $i++){ ?>  
        <td class="td_03" valign="top" height="60">              
           
          <?php echo "<b>$hora:00</b><br />"; ?>
          
          <?php 
          
            switch($dia)
            {
              case 1: $dia_nome = "segunda"; break;
              case 2: $dia_nome = "terca"; break;
              case 3: $dia_nome = "quarta"; break;
              case 4: $dia_nome = "quinta"; break;
              case 5: $dia_nome = "sexta"; break;
            }
          
            for($j = 0; $j < $contador; $j++)
            {
              if(($vetor_oh_hora[$j] == $hora) && ($vetor_oh_dia[$j] == $dia_nome)) 
              {
                 echo "<br />";
                 echo $vetor_nome[$j];
              }
            }
          
          ?>

        </td>
        <?php 
        
            $dia++; 
            
            if($dia == 6) $dia = 1; 
            if($hora == 22) $hora = 10; 
            
            if(($i % 5) == 0)
            { 
              echo "</tr><tr>"; 
              $hora++; 
            } 
          
          } 
        ?>
        
      </tr>
    </table>          
